//
//  NationalBondsJa.m
//  MarketDataColloctor
//
//  Created by jiro on 10/03/27.
//  Copyright 2010 jiro music. All rights reserved.
//

#import "NationalBondsJa.h"
#import "DbConstants.h"

@implementation NationalBondsJa

+ (NationalBondsJa*) nationalBondsJaWithValues: (NSArray*) values
{
	NationalBondsJa* bonds = [ [ NationalBondsJa alloc] init ];
	bonds.code = [ values objectAtIndex: 0 ];
	bonds.name = [ values objectAtIndex: 1 ];
	return bonds;
}

+ (NSString*) tableName
{
	return kText_JaNationalBonds;
}

+ (NSString*) queryCreateTable
{
	NSString* s = [ NSString stringWithFormat:
		@"create table %@ ( %@ %@, %@ %@, %@( %@ ) );",
			[ NationalBondsJa tableName ], 
			kText_Code, kText_Text,
			kText_Name, kText_Text,
			kText_PrimaryKey,  kText_Code
	];
	return s;
}

+ (NSString*) queryInsertInitialValues
{
	NSMutableString* s = [ NSMutableString string ];
	for ( int i = NationalBondsJaType::Year1; i <= NationalBondsJaType::Years40; i++ )
	{
		NationalBondsJa* bond = [ [ NationalBondsJa alloc ] init ];
		bond.code = [ NSString stringWithFormat: @"%d", i ];
		bond.name = NationalBondsJaType::ToString( static_cast< NationalBondsJaType::Type >( i ) );
		if ( i != NationalBondsJaType::Year1 )
		{
			[ s appendString: @", " ];
		}
		[ s appendString: [ bond queryInsertValue ] ];
	}
	return s;
}

- (NSString*) tableName
{
	return [ NationalBondsJa tableName ];
}

- (NSString*) sqlInsertStatement
{
	return [ NSString stringWithFormat:
		@"insert into %@ values %@;",
		[ NationalBondsJa tableName ], [ self queryInsertValue ] ];
}


+ (NSString*) querySelectAll
{
	NSString* s = [ NSString stringWithFormat: @"select * from %@;", [ NationalBondsJa tableName ] ];
	return s;
}

- (NSString*) queryInsert
{
	NSString* s = [ NSString stringWithFormat: @"insert into * values %@;", 
		[ NationalBondsJa tableName ], [ self queryInsertValue ] ];
	return s;
}

- (NSString*) queryInsertValue
{
	return [ NSString stringWithFormat:
		@"( '%@', '%@' )",
		code, name ];
}

@end
